package com.example.pro3_reactor;

import reactor.core.publisher.Flux;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;

/**
 * @program: reactivePro
 * @description: 异步边界  Schedulers.publishOn()   可以将下游的线程切换到其他线程上执行
 * @author: zy
 * @create: 2025-04-26 21:11
 */
public class App4_publishon {
    public static void main(String[] args) {
        // 定义调度器
        Scheduler s = Schedulers.newParallel("parallel", 4);
        // 通过新线程执行，设置异步边界
        final Flux< String > flux = Flux
                .range(1, 2)
                .map(i -> 10 + i)
                .publishOn( s )     // 后续操作切换线程,  异步边界，
                .map(i -> "value " + i);
       new Thread(() -> flux.subscribe(System.out::println)).start();

//        final Flux< String > flux = Flux
//                .range(1, 2)
//                .map(i -> 10 + i)
//                .map(i -> "value " + i);
//        flux.subscribe(System.out::println);

    }
}
